<docs>
  ## 测评完成，匹配职位
</docs>
<template>
  <div class="match">
    <div class="level-wrap">
      <level-select :data="types" @hasChoiced="choiceType"
      :options="{children: 'gwxx', name: 'zymc', subName: 'gwmc'}"></level-select>
    </div>
    <div class="list-wrap">
      <!-- <job-card v-for="(item, index) in data" :job="item.gwmc" :ygxs="item.ygxs_xs"
      :data="item.gwfbsj" :money="item.xcfw" :company="item.dwmc" :zpgwid="item.zpgwid"
      :dwdjid="item.dwdjid"
      :key="index"></job-card> -->

    <pagination-list
      @pullingDown="asyncFetch"
      :no-data="noData"
      class="search-result"
      :ajax-loading="ajaxLoading"
    >
      <position
        v-for="(item,index) in data"
        :key="index"
        :job="item.gwmc"
        :money="item.xcfw"
        :company="item.dwmc"
        :gzdq="item.gzdq"
        :dwdjid="item.dwdjid"
        :zpgwid="item.zpgwid"
        :sftxtdjl="item.sftxtdjl"
        :sfytdjl="item.sfytdjl"
        :xl="item.whcd"
        :sfjpgw="item.sfjpgw"
        :zplxrdh="item.zplxrdh"
        :ygxs="item.ygxs"
        v-model="val"
        @link="link_bank"
      ></position>
    </pagination-list>
      <!-- 投递简历弹框 -->
    <sub-confirm :visible.sync="visibleResume" :jlxx="jlxx" @qrtd="toudi"></sub-confirm>
    </div>
  </div>
</template>
<script>
// import JobCard from 'base/job/job';
import Position from "base/job/jobList";
import PaginationList from 'base/paginationList/paginationList';
import LevelSelect from './levelSelect';

export default {
  name: 'matchJob',
  components: { LevelSelect, Position, PaginationList },
  data() {
    return {
      ajaxLoading: false,
      noData: false,
      visibleResume: false,
      obj:{},
      jlxx: {},
      typeStr: '',
      types: [],
      subTypes: [],
      val:'',
      gwxx: {
        jlid: "",
        zpgwid: "",
        sftxtdjl: "" //是否提醒投递简历   0 提醒；  1不提醒
      },
      data: []
    };
  },
  watch: {
    val: function(val) {
      this.gwxx.zpgwid = val.zpgwid;
      this.gwxx.sftxtdjl = val.sftxtdjl;
      if (val.sftxtdjl === "0") {
        this.visibleResume = true;
      } else {
        this.visibleResume = false;
        this.toudi(1);
      }
    },
  },
  methods: {
    // 获取推荐职位的查询条件
    GET_searchParam() {
      this.$loading = true;
      this.$http
        .get('/grcptj/pptjCx', { params: { zygzs: this.typeStr } })
        .then(result => {
          const resData = result.returnData;
          if (+resData.executeResult === 1) {
            this.types = resData.cxtjlb;
          } else {
            // 再来一个提示
            this.$alert('暂无推荐职位').then(() => {
              this.$router.push({ name: 'testResult' });
            });
          }
          this.$loading = false;
        })
        .catch(() => {
          this.$loading = false;
        });
    },
    // 投递简历
    toudi(data) {
      this.$loading = true;
      data ? (this.gwxx.sftxtdjl = "1") : (this.gwxx.sftxtdjl = "0");
      this.$http.post("/grgl/jltdxxBc", this.gwxx)
        .then(res => {
          if (+res.returnCode === 1) {
            this.visibleResume = false;
            this.$alert(res.returnData.message);
            var _pag = sessionStorage.getItem("page");
            this.data = [];
            this.GET_jobs(this.obj, _pag);
          }
        })
        .finally(() => {
          this.$loading = false;
        });
    },
    //获取简历信息列表
    Resume_list() {
      this.$http.get("/grgl/jlxxCx").then(res => {
        const data = res.returnData;
        this.jlxx = data.jlxx;
        this.gwxx.jlid = this.jlxx.jlid;
      });
    },
    // link_bank跳转
    link_bank(gwid, dwid) {
      this.$router.push({
        name: "newjobDetail",
        query: { dm: gwid, _id: dwid }
      });
    },
    // async fetach data
    asyncFetch(page) {
      this.GET_jobs(this.obj, page);
    },
    // 获取职位列表
    GET_jobs(params, page = 1) {
      params.pageSize = '10';
      params.pageNum = page;
      this.$loading = true;
      this.$http
        .get('/grcptj/ppjgCx', { params })
        .then(result => {
          sessionStorage.setItem("page", page);
          const resData = result.returnData;
          // this.data = resData.zpdwlb;
          // 无查询结果
          if (+resData.executeResult === 0) {
            this.noData = true;
            if (page === 1) {
              this.data = [];
            }
          } else {
            this.noData = false;
            // 有数据
            if (page === 1) {
              this.data = resData.zpdwlb;
            } else {
              this.data = this.data.concat(resData.zpdwlb);
            }
          }
        })
        .finally(() => {
          this.$loading = false;
          this.ajaxLoading = false;
        });
    },
    choiceType(params) {
      if (!params.zygzs) return;
      this.obj = params;
      this.GET_jobs(this.obj);
    }
  },
  created() {
    this.typeStr = this.$route.query.zygzs;
    this.GET_searchParam();
    this.Resume_list();
  }
};
</script>
<style scoped lang="scss">
@import '~common/scss/var.scss';
.list-wrap{
  margin-top: 20px;
}
</style>
